package com.example.ali.service.impl;

import com.example.ali.domain.dto.MyDetectionDto;
import com.example.ali.service.IMyBuildDtoService;
import com.example.ali.util.MyOcrValueHandleUtil;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * 〈检测单数据读取〉
 *
 * @author hero
 * @create 2024/5/29
 * @since 1.0.0
 */
@Service("MyDetectionBuildDtoService")
public class MyDetectionBuildDtoService implements IMyBuildDtoService<MyDetectionDto> {
    @Override
    public List<MyDetectionDto> buildDto(List<Map<String,String>> valueMaplist) {
        List<MyDetectionDto> detectionDtoList = new ArrayList<>();
        valueMaplist.forEach(valueMap ->
                detectionDtoList.add(MyDetectionDto.builder()
                        .purchaseDate(Optional.ofNullable(valueMap.get("0")).orElse(""))
                        .orderNum(MyOcrValueHandleUtil.valueHandler(Optional.ofNullable(valueMap.get("1")).orElse("")))
                        .commonName(Optional.ofNullable(valueMap.get("2")).orElse(""))
                        .sampleFrom(Optional.ofNullable(valueMap.get("3")).orElse(""))
                        .sampleCode(Optional.ofNullable(valueMap.get("4")).orElse(""))
                        .colorAndSmell(Optional.ofNullable(valueMap.get("5")).orElse(""))
                        .oneTime(Optional.ofNullable(valueMap.get("6")).orElse(""))
                        .twoTime(Optional.ofNullable(valueMap.get("7")).orElse(""))
                        .values(MyOcrValueHandleUtil.valueHandler(Optional.ofNullable(valueMap.get("8")).orElse("")))
                        .bulkDensity(MyOcrValueHandleUtil.valueHandler(Optional.ofNullable(valueMap.get("9")).orElse("")))
                        .sampleAllWeight(MyOcrValueHandleUtil.valueHandler(Optional.ofNullable(valueMap.get("10")).orElse("")))
                        .miscWeight(MyOcrValueHandleUtil.valueHandler(Optional.ofNullable(valueMap.get("11")).orElse("")))
                        .build())
        );
        return detectionDtoList;
    }
}